(function (mui, window) {
    var v3AceAuthdata = window.v3AceAuthdata = {};
    var baseRequest = window.baseRequest;
    var appConfig = window.appConfig;
    var commonTool = window.commonTool;
    var dataManager = window.dataManager;
    var locale = dataManager.getLocale();
	var baseUrl = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/restapp/o2oportal';
    //add by dongyi
	var getAuthTempUrl = baseUrl + '/authcfg/query?';
	//获取认证模板列表接口
	v3AceAuthdata.getAuthTemp = function (shopId,callback) {
        baseRequest.commonGet(getAuthTempUrl + mui.param({storeId:shopId}), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data.data);
                } else {
                    callback(1);
                }
            }
        });
    }
	
	var getPageTempUrl = baseUrl + '/themetemplate/query?';
	//获取页面模板列表接口
	v3AceAuthdata.getPageTemp = function (shopId,callback) {
        baseRequest.commonGet(getPageTempUrl + mui.param({storeId:shopId}), 5000, function (code, data) {
            if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data.data);
                } else {
                    callback(1);
                }
            }
        });
    }
    //  end
    //add by ding
    //end
    //add by zhangfuqiang
    // end
    
    // by wangyu
    var deviceInfo = appConfig.v3ServiceUrl + '/ace/oasis/oasis-rest-shop/restshop/deviceinfo?';
    v3AceAuthdata.getDeviceInfo = function(id, callback){
    		baseRequest.commonGet(deviceInfo + $.param({
    			id: id
    		}), 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.code === 0) {
                		callback(0, data.data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var discribeTemplate = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/themetemplate/modify?';
    v3AceAuthdata.getDiscribeTemplate = function(ownerName, storeId, themeName, description, callback){
    		baseRequest.commonPost(discribeTemplate, {
    			ownerName: ownerName,
    			storeId: storeId,
    			themeName: themeName,
    			description: description,
    		}, 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                		callback(0, data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var addTemplate = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/themetemplate/add?';
    v3AceAuthdata.getAddTemplate = function(ownerName, storeId, themeName, description, callback){
    		baseRequest.commonPost(addTemplate, {
    			ownerName: ownerName,
    			storeId: storeId,
    			themeName: themeName,
    			description: description,
    			international: 'cn',
    			themeType: 1,
    			v3flag: 1
    		}, 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                		callback(0, data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var pageTempalteDelet = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/themetemplate/delete?';
    v3AceAuthdata.getPageTemplateDelet = function(ownerName, storeId, themeName, callback){
    		baseRequest.commonPost(pageTempalteDelet, {
    			ownerName: ownerName,
    			storeId: storeId,
    			themeName: themeName
    		}, 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                		callback(0, data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var pageTempalte = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/themetemplate/query?';
    v3AceAuthdata.getPageTeplate = function(ownerName, storeId, startRowIndex, callback){
    		baseRequest.commonGet(pageTempalte + $.param({
    			ownerName: ownerName,
    			storeId: storeId,
    			startRowIndex: startRowIndex,
    			maxItems: 10,
    			ascending: true,
    			v3flag: 1
    		}), 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                		callback(0, data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var visitListDetail = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/registuser/queryUserInfo?';
    v3AceAuthdata.getVisitorListDetail = function(userMac, callback){
    		baseRequest.commonGet(visitListDetail + $.param({
    			userMac: userMac
    		}), 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var joinBlackPeople = appConfig.v3ServiceUrl + '/ace/oasis/auth-data/o2oportal/registuser/addtoblackList';
    v3AceAuthdata.getJoinBlackPeople = function(storeId, userMacList, callback){
    		baseRequest.commonPost(joinBlackPeople, {
    			storeId: storeId,
    			userMacList: userMacList
    		}, 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var deleteBlackPeople = baseUrl + '/registuser/removefromblackList';
    v3AceAuthdata.getDeleteBlackPeople = function(storeId, userMacList, callback){
    		baseRequest.commonPost(deleteBlackPeople, {
    			storeId: storeId,
    			userMacList: userMacList
    		}, 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                 	callback(0,data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var blackPeopleList = baseUrl + '/registuser/queryBlackList?';
    v3AceAuthdata.getBlackPeopleList = function(storeId, startRowIndex, callback){
    		baseRequest.commonGet(blackPeopleList + $.param({
    			storeId: storeId,
    			sortColumn: 'insertTime',
    			ascending: 'false',
    			maxItems: 10,
    			startRowIndex: startRowIndex
    		}), 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var visitorList = baseUrl + '/registuser/query?';
    v3AceAuthdata.getVisitorList = function(storeId, startRowIndex, callback){
    		baseRequest.commonGet(visitorList + $.param({
    			storeId: storeId,
    			sortColumn: 'lastAccessTime',
    			ascending: 'false',
    			maxItems: 10,
    			startRowIndex: startRowIndex
    		}), 10000, function(code, data){
    			if (code === 2 || code === 1) {
                return callback(2);
            }
            if (code === 0) {
                if (data.errorcode === 0) {
                	callback(0,data);
                } else {
                    callback(1);
                }
            }
    		})
    }
    
    var alarmInfomation = appConfig.v3ServiceUrl + '/ace/oasis/oasis-alarm/sendmsg/getall';
    v3AceAuthdata.getAlarmInfomation = function(userName, starTime, endTime, callback){
    		baseRequest.commonPost(alarmInfomation, {
    			userName: userName,
    			startTime: starTime,
    			endTime: endTime
    		}, 10000, function(code, data){
    			if(code === 0){
				if(data == -1 || data.errmsg == 'fail') {
					callback(1);
				} else {
					callback(0, data.data);
				}
			}
			if(code === 1 || code ===2){
				return callback(2);
			}
    		})
    }
    //end
}(mui, window));